package com.dongdongshop.servcice.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.pojo.TbBrandExample;
import com.dongdongshop.service.BrandService;
import com.dongdongshop.util.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Service
@Component
public class BrandServiceImpl implements BrandService {
    @Resource
    private TbBrandMapper brandMapper;
    //开启日志
    Logger logger = LoggerFactory.getLogger(BrandServiceImpl.class);

    // 查询方法
    @Override
    public PageBean<TbBrand> getBrandInfo(Integer pageNumber,Integer pageSize) {
        PageBean<TbBrand> page = new PageBean<>();
        page.setPageNumber(pageNumber);
        page.setPageSize(pageSize);
        List<TbBrand> list = brandMapper.getBrandTotalAndSize(page.getStartIndex(),pageSize);
        List<TbBrand> brands = brandMapper.selectByExample(new TbBrandExample());
        page.setTotalCount(brands.size());
        page.setResult(list);
        return page;
    }
    // 增加方法
    @Override
    public void insertBrand(TbBrand brand) {
        brandMapper.insertSelective(brand);
    }

    @Override
    public TbBrand updateBrandInfo(Long id) {
        return brandMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateBrand(TbBrand brand) {
        brandMapper.updateByPrimaryKeySelective(brand);
    }

    @Override
    public void deleteBatch(Integer[] ids) {
        brandMapper.deleteBatch(ids);
    }
    //查询所有品牌信息，不加分页
    @Override
    public List<TbBrand> getBrandAllInfo() {
        List<TbBrand> brands = brandMapper.selectByExample(new TbBrandExample());
        return brands;
    }
}
